package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.StudentBean;

import com.project.mapper.IStudentMapper;
import com.project.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private IStudentMapper stuMapper;


    @Override
    public IPage<StudentBean> findByItem(Integer pageNO, String stuName, String className, String roomAddress) {
//        QueryWrapper<StudentBean> qw = new QueryWrapper<>();
//        if (stuName!=null&&stuName.length()!=0){
//            qw.like("s_stuName",stuName);
//        }
//        if (className!=null&&className.length()!=0){
//            qw.ge("c_className",className);
//        }
//        if (roomAddress!=null&&roomAddress.length()!=0){
//            qw.le("r_address",roomAddress);
//        }
        return stuMapper.findByItem(new Page(pageNO,5),stuName,className,roomAddress);
    }

    @Override
    public StudentBean findById(Integer stuId) {
        return stuMapper.selectById(stuId);
    }

    @Override
    public void addStu(StudentBean stu) {

       stuMapper.insert(stu);
    }

    @Override
    public void delStu(Integer stuId) {
        stuMapper.deleteById(stuId);
    }

    @Override
    public void changeRoom(Integer stuId, Integer roomId) {
        StudentBean stu=stuMapper.selectById(stuId);
        stu.setRoomId(roomId);
        stuMapper.updateById(stu);

//        stuMapper.changeRoom(stuId,roomId);
    }
}
